package reflectDemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-08-23
 * Time: 22:14
 */

class Student{
    //私有属性name
    private String name = "bit"; //公有属性age

    public int age = 18;

    //不带参数的构造方法
    public Student(){
        System.out.println("Student()");
    }

    private Student(String name,int age) {
        this.name = name;
        this.age = age;
            System.out.println("Student(String,name)");
    }

    private void eat(){
        System.out.println("i am eat");
    }

    public void sleep(){
        System.out.println("i am pig");
    }

    private void function(String str) {
        System.out.println(str);
    }

 @Override
 public String toString() {
    return "Student{" +
         "name='" + name + '\'' +
         ", age=" + age +
         '}';
         }
}


public class Test {


    /**
     *  反射获取 Class对象 的三种方式:
     */
    public static void main(String[] args) throws ClassNotFoundException {
        //1.
        Class<?> c1 = Class.forName("reflectDemo.Student");
        //2.
        Student student = new Student();
        Class<?> c2 = student.getClass();
        //3.
        Class<?> c3 = Student.class;

        System.out.println(c1 == c2);
        System.out.println(c1 == c3);
        System.out.println(c3 == c2);
        //三个结果都是 true  说明 Class对象 只有一个
    }
}
